#!/usr/bin/python
# encoding: utf-8
class bmr():
    """
    计算能量消耗
    """

    def __init__(self):
        self.type = {"久坐": 1.2, "轻运动": 1.375, "中等运动": 1.55, "剧烈运动": 1.725, "运动员": 1.9}  # 运动类型
        self.user_type = {"0": "久坐", "1": "轻运动", "2": "中等运动", "3": "剧烈运动", "4": "运动员"}

    def nutrition(self, tdee):
        """
        计算摄入能量
        """
        return {"营养建议": {"中等碳水化合物": {"蛋白质": int(tdee * 0.4 / 4), "脂肪": int(tdee * 0.4 / 9),
                                     "碳水化合物": int(tdee * 0.2 / 4)},
                         "低等碳水化合物": {"蛋白质": int(tdee * 0.3 / 4), "脂肪": int(tdee * 0.35 / 9),
                                     "碳水化合物": int(tdee * 0.35 / 4)},
                         "高等碳水化合物": {"蛋白质": int(tdee * 0.3 / 4), "脂肪": int(tdee * 0.2 / 9),
                                     "碳水化合物": int(tdee * 0.5 / 4)}}}

    def calc(self, data):
        """
        主函数data = {"gender": "1", "sport_type": '0', "age": "35", "weight": "55", "height": "170", "body_fat": "参数可选"}
        """
        age = int(data['age'])
        weight = float(data['weight'])
        height = float(data['height'])
        if data['BF'] != '':
            zhi_fang = int(data['BF']) / 100
        elif data['gender'] == '男':
            zhi_fang = 0.23
        else:
            zhi_fang = 0.3324
        bmr = int(10 * weight + 6.25 * height - 5 * age - 1620 * zhi_fang + 377.5) * self.type[data['ST']]
        result = {'bmr': bmr}
        result.update(self.nutrition(bmr))
        return result


if __name__ == '__main__':
    data = {"gender": "男", "ST": '轻运动', "age": "35", "weight": "55", "height": "170", "BF": ""}
    print(bmr().calc(data))
